<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript">
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							toolbar : [ {
								id : listDisplayEId + '_btn_add',
								text : '采购金额审核通过',
								iconCls : 'icon-add',
								handler : function() {
									var row = $('#'+listDisplayEId).datagrid('getSelections');
                                    if(row.length == 0){
                                        $.messager.alert('提示','请选择一条记录操作！','info');
                                        return;
                                    }else{
                                        //var str = "ordId="+row[0]['ordId']; 
                                        
                                        /* if(row[0]['ordState'] != 1){
                                            $.messager.alert('提示','所选择的状态不正确！','info');
                                            return;
                                        } */
                                        
                                        var dateone = '{"ordId":"'+ row[0]['ordId']+'","ordSupId":"'+row[0]['ordSupId'] +'"}';

                                        dataOneJson =JSON.parse(dateone);

                                        $.messager.confirm('提示', '是否审核通过该条记录？', function(r){
                                            if (r){         
                                                $.ajax({type:'post',url:"<c:url value='/order/passOrderValueForPurchase.do'/>",type : "post",
                                                    dataType: "json",
                                                    data: $.param(dataOneJson),//设置查询参数及提交路径
                                                success:function(data){
                                                    if(data.success){
                                                        $.messager.alert("提示", "审核成功！", 'info');
                                                        $('#'+listDisplayEId).datagrid('reload');
                                                    }else{
                                                        $.messager.alert("提示", data.msg, 'warning');
                                                    }
                                                },
                                                error:function(){
                                                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                                }
                                                });
                                            } 
                                            $('#'+listDisplayEId).datagrid('reload');
                                            $('#'+listDisplayEId).datagrid('clearSelections');
                                        });
                                    }
                                    $('#'+listDisplayEId).datagrid('clearSelections');
								}
							}

							],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
							}
						});

	};
	$(document).ready(function() {
		initList('listDisplay');
	});

	function goDetailedContent(val, rowData, rowIndex) {
		return '<a href="#" onclick="constructionManager(\'' + rowData.ordId
				+ '\',\'' + rowData.ordSupId + '\')">' + val + '</a>  '
	}

	function constructionManager(id, supId) {
		//window.showModalDialog("<c:url value='/order/goCustomDetailed.do'/>"+"?id="+id, "","dialogWidth=1200px;dialogHeight=500px,status=no");
		var new_win = window.open(
				"<c:url value='/jsp/openIndexSun.jsp?url=/order/goCustomDetailedForAdmin.do'/>"
						+ "?id=" + id + "&supId=" + supId, "sun",
				"width=1200px,height=600px,status=no,scrollbars=yes");
		new_win.focus();
	}
	//下拉框
	$(function() {
		// 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		$('#ordState').combobox({
			data : [ {
				"ordState" : "0",
				"ordStateName" : "全部"
			}, {
				"ordState" : "1",
				"ordStateName" : "待定品级"
			}, {
				"ordState" : "2",
				"ordStateName" : "待录实际需求重量"
			}, {
				"ordState" : "3",
				"ordStateName" : "待发货"
			}, {
				"ordState" : "4",
				"ordStateName" : "待收货"
			}, {
				"ordState" : "5",
				"ordStateName" : "采购已审核"
			} ],
			editable : false, //不可编辑状态  
			cache : false,
			valueField : 'ordState',
			textField : 'ordStateName',
		});
	});
	function searchInfo() {
		if ($('#ordState').combobox('getValue') == '') {
			$('#listDisplay').datagrid('load', {
				ordState : 0,
				ordDate : $('#ordDate').datebox('getValue'),
				ordCustName : $('#ordCustName').val()
			});
		} else {
			$('#listDisplay').datagrid('load', {
				ordState : $('#ordState').combobox('getValue'),
				ordDate : $('#ordDate').datebox('getValue'),
				ordCustName : $('#ordCustName').val()
			});
		}
	}
	// 颜色
	function cellStyler(value, row, index) {
		if (row['ordPaymentState'] == 1) {
			return 'color:red;';
		}
	}
</script>
</head>

<body>
	<table>
		<tr>
			<td>
				<div
					style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
					class="easyui-panel" title="查询" iconCls="icon-search"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">
					<form id="searchForm" name="searchForm" method="post"
						action="userlist.txt"
						onsubmit="return searchDGData(this.id,'listDisplay');">
						<div>
							<table cellpadding="5">
								<tr>
									<td>店长名：</td>
									<td><input class="easyui-validatebox" id="ordCustName"
										name="ordCustName"></input></td>
									<td>订单状态：</td>
									<td><input class="easyui-combobox" id="ordState"
										editable="false" name="ordState"></input></td>
									<td>订单日期：</td>
									<td><input class="easyui-datebox" editable="true"
										id="ordDate" name="ordDate"></input></td>
									<td><input type="button" onclick="searchInfo()" value="查询"></td>
								</tr>
							</table>
						</div>
					</form>
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<table id="listDisplay" title="供应商订单列表" singleSelect=true
					iconCls="icon-list" idField="id"
					url="<c:url value="/order/findcustMaterOrderAll.do"/>"
					style="width: 800px; width: 1180px;" loadMsg="请稍候......"
					pagination="true" pageSize="10"
					pageList="[10,20,30,40,50,100,150,200]" sortName="roleId"
					rownumbers="true" sortOrder="asc">
					<thead>
						<tr>
							<th field="id" width="25" align="center" checkbox="true"></th>
							<th field="ordId" width="80" sortable="true">订单ID</th>
							<th field="ordCustId" width="80" sortable="true">客户ID</th>
							<th field="ordCustName" width="80" sortable="true">客户名</th>
							<th field="ordSupId" width="80" sortable="true">供货商ID</th>
							<th field="ordSupName" width="80" sortable="true">供货商名</th>
							<th field="ordState" width="80" formatter="formatOrdStateSupper"
								sortable="true">订单状态</th>
							<th field="ordPaymentState" width="80"
								formatter="formatOrdPaymentState" sortable="true"
								styler="cellStyler">结款状态</th>
							<th field="commitDeliverState" width="80"
								formatter="formatCommitDeliverState" sortable="true">材料实际重量
							</th>
							<th field="ordDate" width="80" formatter="formatDGField"
								sortable="true">订单日期</th>
							<th field="ordDay" width="60" formatter="formatDGField"
								sortable="true">订单日</th>
							<th field="ordValue" width="100" sortable="true">需求总价</th>
							<th field="ordValueReal" width="100" sortable="true">实际送货总价
							</th>
							<th field="content" width="100" formatter="goDetailedContent"
								sortable="true">查看订单详细内容</th>

						</tr>
					</thead>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>